var express = require('express')
  , discApi = require('./api/discussion')
  , commApi = require('./api/comment')
  , http = require('http')
  , path = require('path');

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 1099);
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
});

app.configure('development', function()
{
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function()
{
    app.use(express.errorHandler());
});

app.get('/api/discussions', discApi.list);
app.get('/api/discussions/:id?', discApi.get);
app.post('/api/discussions', discApi.add);
app.delete('/api/discussions/:id', discApi.delete);

app.get('/api/comments', commApi.list);
app.get('/api/comments/:id?', commApi.get);
app.post('/api/comments', commApi.add);
app.delete('/api/comments/:id', commApi.delete);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Sample api server running on port " + app.get('port'));
});
